package com.qianfeng.zhangwei.volley;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ContentView;
import com.lidroid.xutils.view.annotation.ViewInject;

/**
 * Created by Administrator on 2015/8/4.
 */
@ContentView(R.layout.item)
public class UtilsTestAdapter extends BaseAdapter {
    private final String[] lists;
    private final Context context;
    private final LayoutInflater inflate;

    public UtilsTestAdapter(Context context,String[] lists) {
        this.lists = lists;
        this.context = context;
        this.inflate = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return lists!=null&&lists.length>0?lists.length:0;
    }

    @Override
    public Object getItem(int i) {
        return lists[i];
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if(view==null){
            view = inflate.inflate(R.layout.item,null);
            holder = new ViewHolder(view);
            view.setTag(holder);
        }else {
            holder = (ViewHolder) view.getTag();
        }
        holder.item.setText(lists[i]);
        return view;
    }
    private static class ViewHolder{
        @ViewInject(R.id.item)private TextView item;

        public ViewHolder(View view) {
            ViewUtils.inject(this,view);
        }
    }
}
